﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace RemoteDesktop
{
    /// <summary>
    /// ConfigWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ConfigWindow : Window
    {
        string mIpAddress = "";
        string sIpAddress1 = "";
        string mRoleType = "";
        string mIpAddressPort = "";
        string sIpAddress1Port = "";
        string mIpAddressRole = "";
        string sIpAddress1Role = "";
        Context context = null;
        public ConfigWindow()
        {
            InitializeComponent();
            context = Context.Get();
            mIpAddress = context.IpAddress;
            sIpAddress1 = context.ServerIpAddress1;
            mRoleType = context.RoleType;
            mIpAddressPort = context.IpAddressPort;
            sIpAddress1Port = context.ServerIpAddress1Port;
            mIpAddressRole = context.IpAddressRole;
            sIpAddress1Role = context.ServerIpAddress1Role;
            if (mIpAddress != null)
            {
                IpAddress.Text = mIpAddress;
            }
            if (sIpAddress1 != null)
            {
                ServerIpAddress1.Text = sIpAddress1;
            }
            if (mIpAddressPort != null)
            {
                IpAddressPort.Text = mIpAddressPort;
            }
            if (sIpAddress1Port != null)
            {
                ServerIpAddress1Port.Text = sIpAddress1Port;
            }
            if (mIpAddressRole != null)
            {
                IpAddressRole.Text = mIpAddressRole;
            }
            if (sIpAddress1Role != null)
            {
                ServerIpAddress1Role.Text = sIpAddress1Role;
            }
            if (mRoleType == "发送方")
            {
                RoleType01.IsChecked = true;
            }else if (mRoleType == "接收方")
            {
                RoleType02.IsChecked = true;
            }
        }

        private void SaveConfig(object sender, RoutedEventArgs e)
        {
            mIpAddress = IpAddress.Text;
            sIpAddress1 = ServerIpAddress1.Text;
            mIpAddressPort = IpAddressPort.Text;
            sIpAddress1Port = ServerIpAddress1Port.Text;
            mIpAddressRole = IpAddressRole.Text;
            sIpAddress1Role = ServerIpAddress1Role.Text;
            PLogs.UpdateSettingString("ip_address", mIpAddress);
            PLogs.UpdateSettingString("server_ip_address1", sIpAddress1);
            PLogs.UpdateSettingString("role_type", mRoleType);
            PLogs.UpdateSettingString("ip_address_port", mIpAddressPort);
            PLogs.UpdateSettingString("server_ip_address1_port", sIpAddress1Port);
            PLogs.UpdateSettingString("ip_address_role", mIpAddressRole);
            PLogs.UpdateSettingString("server_ip_address1_role", sIpAddress1Role);
            context.IpAddress = mIpAddress;
            context.ServerIpAddress1 = sIpAddress1;
            context.RoleType = mRoleType;
            context.IpAddressPort = mIpAddressPort;
            context.ServerIpAddress1Port = sIpAddress1Port;
            context.IpAddressRole = mIpAddressRole;
            context.ServerIpAddress1Role = sIpAddress1Role;
            this.Close();
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = e.Source as RadioButton;
            mRoleType = radioButton.Content.ToString();
        }
    }
}
